/**
 * 套餐分类
 *
 * @project sky-take-out2
 * @author MECHREVO
 * @date 2023/12/2 17:45:42
 * @version 1.0
 */
package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "套餐分类接口")
@RequestMapping("/admin/setmeal")
public class SetMealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 添加套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    public Result AddSetMeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.addSetMeal(setmealDTO);
        return Result.success();
    }

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询套餐")
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询套餐{}",setmealPageQueryDTO);
        PageResult pageResult= setmealService.page(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除套餐
     * @param ids
     * @return
     */
    @ApiOperation("删除套餐")
    @DeleteMapping
    public Result Delete(@RequestParam List<Long> ids){
        log.info("删除套餐{}",ids);
        setmealService.DeleteSetMeal(ids);
        return Result.success();
    }
@ApiOperation("根据id进行套餐回显")
@GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
      log.info("根据id进行套餐回显{}",id);
      SetmealVO setmealvo=setmealService.getById(id);
      return Result.success(setmealvo);
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return  Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售停售")
    public Result modifyStatus(Long id,@PathVariable Integer status){
        setmealService.modifyStatus(id,status);
        return Result.success();
    }
}
